using System;

namespace Mbl.ParameterizedTest.FluentCollectionBuilding.Expectors
{
    public abstract class PredicateExpectation<T> : IExpectation<T>
    {
        private readonly Func<T, bool> _predicate;

        protected PredicateExpectation(Func<T, bool> predicate)
        {
            _predicate = predicate;
        }

        protected abstract string GetErrorMessage(T actual);

        public AssertionResult HoldsFor(Func<T> actualGenerator)
        {
            var actual = actualGenerator();
            if (_predicate(actual))
            {
                return AssertionResult.Success;
            }

            return AssertionResult.Error(GetErrorMessage(actual));
        }
    }
}